package graduate.wangyaqi.ProgrammeQuestions;

import graduate.wangyaqi.OnlyQuestions.OnlyQuestions;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class ProgrammeQuestionsService {
    @Resource
    private ProgrammeQuestionsRepository programmeQuestionsRepository;

    //保存数据
    @Transactional
    public void save(ProgrammeQuestions programmeQuestion) {
        programmeQuestionsRepository.save(programmeQuestion);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        programmeQuestionsRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<ProgrammeQuestions> getAll() {
        Iterable<ProgrammeQuestions> programmeQuestions = programmeQuestionsRepository.findAll();
        return programmeQuestions;
    }

    @Transactional
    public Iterable<ProgrammeQuestions> getAllByTaotiID(int id){
        Iterable<ProgrammeQuestions> list = programmeQuestionsRepository.findAllByTaotiID(id);
        return list;
    }
    @Transactional
    public Optional<ProgrammeQuestions> findById(Long aLong){
        return programmeQuestionsRepository.findById(aLong);
    };

    @Transactional
    public int countAllByStuIDadnAndTaotiID(Long taotaoId ){
        return programmeQuestionsRepository.countAllByTaotiID(taotaoId);
    }

    @Transactional
    public ProgrammeQuestions getFirstByTaotiIDAndIdIsGreaterThan(long taotiId, long id){
        return programmeQuestionsRepository.getFirstByTaotiIDAndIdGreaterThan(taotiId,id);
    }

    @Transactional
    public ProgrammeQuestions getFirstByTaotiIDAndIdIsLessThan(long taotiId, long id){
        return programmeQuestionsRepository.getFirstByTaotiIDAndIdLessThanOrderByIdDesc(taotiId,id);
    }
}
